﻿using System;
using System.Linq;
using Model;

namespace BLL
{
    public class Sys_UsersInRoles_BLL
    {
        ExtendedDBModelContainer _db = new ExtendedDBModelContainer();

        public Sys_UsersInRoles Get(Guid Sys_UsersId, Guid Sys_RolesId)
        {
            return _db.Sys_UsersInRoles.SingleOrDefault(a => a.Sys_UsersId.Equals(Sys_UsersId) && a.Sys_RolesId.Equals(Sys_RolesId));
        }

        public void Insert(Guid Sys_UsersId, Guid Sys_RolesId)
        {
            var item = new Sys_UsersInRoles() { Id = Guid.NewGuid(), Sys_UsersId = Sys_UsersId, Sys_RolesId = Sys_RolesId };
            _db.Sys_UsersInRoles.AddObject(item);
            _db.SaveChanges();
        }

        public void Delete(Guid Sys_UsersId, Guid Sys_RolesId)
        {
            var item = Get(Sys_UsersId, Sys_RolesId);
            if (item != null)
            {
                _db.Sys_UsersInRoles.DeleteObject(item);
                _db.SaveChanges();
            }
        }
    }
}
